from django.contrib import admin

# Register your models here.
from django.contrib.auth.admin import UserAdmin
from .models import myUser

# from django.utils.translation import gettext_lazy
from django.utils.translation import gettext_lazy as _


admin.site.site_title = "通用接口API管理系统-后台管理"
admin.site.site_header = "通用接口API管理系统-后台管理^_^"


@admin.register(myUser)
class myUser_Admin(UserAdmin):
    list_display = [
        "idcard",
        "username",
        "company",
        "department",
        "workshop",
        "position",
        "is_see",
        "is_edit",
        "is_delete",
        "is_auditor",
        "is_area",
        "area",
        "role",
        "base",
    ]
    search_fields = list_display
    list_filter = list_display
    # 设置哪些字段可以点击进入编辑界面
    list_display_links = ("idcard", "username")
    # 编辑用户信息时的表单页面字段设置
    fieldsets = (
        (
            "注册用户名和密码",
            {
                "fields": (
                    "username",
                    "password",
                )
            },
        ),
        (
            "用户信息",
            {
                "fields": (
                    "idcard",
                    "company",
                    "department",
                    "workshop",
                    "position",
                    "email",
                    "area",
                    "role",
                    "base",
                )
            },
        ),
        (
            _("Permissions"),
            {
                "fields": (
                    "is_active",
                    "is_staff",
                    "is_superuser",
                    "groups",
                    "user_permissions",
                ),
            },
        ),
        (_("Important dates"), {"fields": ("last_login", "date_joined")}),
    )
    # 新增用户时的表单页面字段设置
    add_fieldsets = (
        (
            "注册用户名和密码",
            {
                "classes": ("wide",),
                "fields": ("username", "password1", "password2"),
            },
        ),
    )
